<?php

class task1
{
    //$nextTask为task2
    public function __invoke($nextTask)
    {
        echo "task-1\n";
        return $nextTask();
    }
}

class task2
{
    public function __invoke($nextTask)
    {
        echo "task-2\n";
        return $nextTask();
        // TODO: Implement __invoke() method.
    }
}

class task3
{
    //最后一个不需要传递nextTask
    public function __invoke()
    {
        echo "task-3\n";
        return 'abc';
        // TODO: Implement __invoke() method.
    }
}

include __DIR__ . "/invoke.php";

$taskList = [new task1(),new task2(),new task3()];

$invoke = new MiddlewareRunnerTest($taskList);
$a = $invoke();
var_dump($a);